package com.linkoog.devtools.archive.filesystem.sevenzip;

import com.linkoog.devtools.archive.filesystem.ArchiveBasedFileSystem;
import com.intellij.openapi.fileTypes.FileTypeRegistry;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.openapi.vfs.impl.ArchiveHandler;
import com.intellij.openapi.vfs.newvfs.VfsImplUtil;
import org.jetbrains.annotations.NotNull;

/**
 */
public abstract class SevenZipFileSystem extends ArchiveBasedFileSystem {

    public static final String PROTOCOL = SevenZipFileType.INSTANCE.getDefaultExtension();

    public static SevenZipFileSystem getInstance() {
        return (SevenZipFileSystem)VirtualFileManager.getInstance().getFileSystem(PROTOCOL);
    }

    @Override
    protected ArchiveHandler getHandler(@NotNull VirtualFile entryFile) {
        return VfsImplUtil.getHandler(this, entryFile, SevenZipFileHandler::new);
    }

    @Override
    protected boolean isCorrectFileType(@NotNull VirtualFile local) {
        return FileTypeRegistry.getInstance().getFileTypeByFileName(local.getName()) == SevenZipFileType.INSTANCE;
    }

}